package pers.qianyu.module.image.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import pers.qianyu.module.core.domain.image.dataobj.LabelCountDO;
import pers.qianyu.module.core.domain.image.entity.LabelPO;

import java.util.List;

/**
 * @author mizzle rain
 * @date 2021-04-22 14:10
 */
@Mapper
public interface LabelDao extends BaseMapper<LabelPO> {
    @Select("select lil.label_id label_id, count(1) label_count, ll.name label_name\n" +
            "from lamb_image_label lil\n" +
            "         left join lamb_label ll\n" +
            "                   on lil.label_id = ll.id\n" +
            "where ll.deleted = 0\n" +
            "  and lil.deleted = 0\n" +
            "group by lil.label_id;")
    List<LabelCountDO> findAllTagsCount();

    @Select("select distinct lil.image_id\n" +
            "from lamb_image_label lil\n" +
            "         left join lamb_label ll\n" +
            "                   on ll.id = lil.label_id\n" +
            "where ll.deleted = 0\n" +
            "  and lil.deleted = 0\n" +
            "  and ll.name like #{labelName};")
    List<Long> selectImageIdsByLabelName(@Param("labelName") String labelName);
}
